const posters = [
  "https://www.w3schools.com/w3images/lights.jpg",
  "https://www.w3schools.com/w3images/fjords.jpg",
  "https://www.w3schools.com/w3images/mountains.jpg",
  "https://www.w3schools.com/w3images/forest.jpg",
  "https://www.w3schools.com/w3images/nature.jpg",
  "https://www.w3schools.com/w3images/snow.jpg",
  "https://www.w3schools.com/w3images/rocks.jpg",
  "https://www.w3schools.com/w3images/bridge.jpg",
  "https://www.w3schools.com/w3images/flowers.jpg",
  "https://www.w3schools.com/w3images/lights.jpg",
  "https://www.w3schools.com/w3images/fjords.jpg",
  "https://www.w3schools.com/w3images/mountains.jpg",
  "https://www.w3schools.com/w3images/forest.jpg",
  "https://www.w3schools.com/w3images/nature.jpg",
  "https://www.w3schools.com/w3images/snow.jpg",
  "https://www.w3schools.com/w3images/rocks.jpg",
  "https://www.w3schools.com/w3images/bridge.jpg",
  "https://www.w3schools.com/w3images/flowers.jpg",
  "https://www.w3schools.com/w3images/lights.jpg",
  "https://www.w3schools.com/w3images/fjords.jpg",
  "https://www.w3schools.com/w3images/mountains.jpg",
  "https://www.w3schools.com/w3images/forest.jpg",
  "https://www.w3schools.com/w3images/nature.jpg",
  "https://www.w3schools.com/w3images/snow.jpg",
  "https://www.w3schools.com/w3images/rocks.jpg",
  "https://www.w3schools.com/w3images/bridge.jpg",
  "https://www.w3schools.com/w3images/flowers.jpg",
  "https://www.w3schools.com/w3images/lights.jpg",
  "https://www.w3schools.com/w3images/fjords.jpg",
  "https://www.w3schools.com/w3images/mountains.jpg",
  "https://www.w3schools.com/w3images/forest.jpg",
  "https://www.w3schools.com/w3images/nature.jpg",
  "https://www.w3schools.com/w3images/snow.jpg",
  "https://www.w3schools.com/w3images/rocks.jpg",
  "https://www.w3schools.com/w3images/bridge.jpg",
  "https://www.w3schools.com/w3images/flowers.jpg",
  "https://www.w3schools.com/w3images/lights.jpg",
  "https://www.w3schools.com/w3images/fjords.jpg",
  "https://www.w3schools.com/w3images/mountains.jpg",
  "https://www.w3schools.com/w3images/forest.jpg",
  "https://www.w3schools.com/w3images/nature.jpg",
  "https://www.w3schools.com/w3images/snow.jpg",
  "https://www.w3schools.com/w3images/rocks.jpg",
  "https://www.w3schools.com/w3images/bridge.jpg",
  "https://www.w3schools.com/w3images/flowers.jpg",
  "https://www.w3schools.com/w3images/lights.jpg",
  "https://www.w3schools.com/w3images/fjords.jpg",
  "https://www.w3schools.com/w3images/mountains.jpg",
  "https://www.w3schools.com/w3images/forest.jpg",
  "https://www.w3schools.com/w3images/nature.jpg",
  "https://www.w3schools.com/w3images/snow.jpg",
  "https://www.w3schools.com/w3images/rocks.jpg",
  "https://www.w3schools.com/w3images/bridge.jpg",
  "https://www.w3schools.com/w3images/flowers.jpg",
  "https://www.w3schools.com/w3images/lights.jpg",
  "https://www.w3schools.com/w3images/fjords.jpg",
  "https://www.w3schools.com/w3images/mountains.jpg",
  "https://www.w3schools.com/w3images/forest.jpg",
  "https://www.w3schools.com/w3images/nature.jpg",
  "https://www.w3schools.com/w3images/snow.jpg",
  "https://www.w3schools.com/w3images/rocks.jpg",
  "https://www.w3schools.com/w3images/bridge.jpg",
  "https://www.w3schools.com/w3images/flowers.jpg",
  "https://www.w3schools.com/w3images/lights.jpg",
  "https://www.w3schools.com/w3images/fjords.jpg",
  "https://www.w3schools.com/w3images/mountains.jpg",
  "https://www.w3schools.com/w3images/forest.jpg",
  "https://www.w3schools.com/w3images/nature.jpg",
  "https://www.w3schools.com/w3images/snow.jpg",
  "https://www.w3schools.com/w3images/rocks.jpg",
  "https://www.w3schools.com/w3images/bridge.jpg",
  "https://www.w3schools.com/w3images/flowers.jpg",
  "https://www.w3schools.com/w3images/lights.jpg",
  "https://www.w3schools.com/w3images/fjords.jpg",
  "https://www.w3schools.com/w3images/mountains.jpg",
  "https://www.w3schools.com/w3images/forest.jpg",
  "https://www.w3schools.com/w3images/nature.jpg",
  "https://www.w3schools.com/w3images/snow.jpg",
  "https://www.w3schools.com/w3images/rocks.jpg",
  "https://www.w3schools.com/w3images/bridge.jpg",
  "https://www.w3schools.com/w3images/flowers.jpg",
  "https://www.w3schools.com/w3images/lights.jpg",
  "https://www.w3schools.com/w3images/fjords.jpg",
  "https://www.w3schools.com/w3images/mountains.jpg",
  "https://www.w3schools.com/w3images/forest.jpg",
  "https://www.w3schools.com/w3images/nature.jpg",
  "https://www.w3schools.com/w3images/snow.jpg",
  "https://www.w3schools.com/w3images/rocks.jpg",
  "https://www.w3schools.com/w3images/bridge.jpg",
  "https://www.w3schools.com/w3images/flowers.jpg"
];




const videos = [
  "https://www.w3schools.com/html/mov_bbb.mp4",  // W3Schools 提供的简单测试视频 (Big Buck Bunny)
  "https://www.w3schools.com/html/movie.mp4",    // W3Schools 提供的短视频示例
];








const categories = ["国内", "国际","财经","科技","娱乐","体育","政治","文化"];
const authors = ["张三", "李四", "王五", "赵六", "孙七"];
const sampleTitles = [
  "人工智能引领未来发展",
  "气候变化成为全球关注焦点",
  "国内新型产业园开幕",
  "体育健儿奋勇拼搏再创佳绩",
  "明星婚礼成为焦点话题",
  "国际合作推动科技进步",
  "教育改革持续深入推进",
  "新能源车销量再创新高",
  "医疗技术突破性进展",
  "数字经济加速崛起",
  "大数据时代改变生活方式",
  "环保政策再升级，守护蓝天",
  "科技新品发布会引关注",
  "房地产市场走势平稳",
  "国内文化遗产保护受关注",
  "全球通胀压力仍在加大",
  "电竞行业迎来黄金时代",
  "娱乐圈新生代演员崭露头角",
  "国际峰会达成重要协议",
  "新冠疫苗研发取得新突破",
  "国内旅游业强势复苏",
  "航天技术迎来新里程碑",
  "人工智能伦理问题引发热议",
  "网络安全成为国家重点",
  "生态修复计划成效显著",
  "电商平台促销引爆消费热潮",
  "科技巨头投资元宇宙",
  "学术界迎来重要科研成果",
  "新能源领域持续发力",
  "电影节开幕，佳作云集",
  "国内制造业焕发新生机",
  "国际冲突持续升级",
  "艺术展览吸引大量观众",
  "机器人产业迈向新高度",
  "健康生活方式成为新潮流",
  "自动驾驶技术迎来突破",
  "互联网医疗受用户热捧",
  "音乐节盛大举行，观众爆满",
  "国内5G网络建设再提速",
  "国际体育赛事传递友谊",
  "农业现代化助力乡村振兴",
  "深空探测任务取得进展",
  "科技创业者分享创新经验",
  "家庭教育法落地实施",
  "大健康产业快速发展",
  "国际艺术交流成果丰硕",
  "智能家居走进千家万户",
  "汽车产业电动化趋势明显",
  "跨国公司加码国内投资",
  "新兴城市吸引高端人才"
];

const sampleContentParagraphs = [
  "这是新闻内容的一部分，展示了丰富的信息。",
  "详细描述了当前新闻的背景和细节。",
  "最新的新闻动态引发了广泛关注。",
  "这条新闻的重点在于事件的发展经过。",
  "分析了事件背后的深层原因。",
  "多方观点汇聚，为读者提供了全面的视角。",
  "结合历史和现状，对未来趋势进行了预测。",
  "权威专家对事件影响发表了深度解读。",
  "社会各界对此事件的反应也颇为强烈。",
  "通过数据分析展示了事件的相关影响。"
];

const fixedPosters = [
  "https://p4.img.cctvpic.com/photoAlbum/page/performance/img/2023/4/11/1681184068440_56.png",
  "https://p3.img.cctvpic.com/photoAlbum/page/performance/img/2023/4/23/1682216718758_977.jpg",
  "https://p4.img.cctvpic.com/photoAlbum/page/performance/img/2023/6/14/1686737015088_957.png"
];



// 获取数组中的随机元素
function getRandomItem(array) {
  return array[Math.floor(Math.random() * array.length)];
}

// 生成至少1000个字符的内容，确保没有换行
function generateRandomContent() {
  let content = "";
  while (content.length < 5000) {
    content += getRandomItem(sampleContentParagraphs);
  }
  return content;
}

// 生成评论数据
function generateComments(newsId, count) {
  return Array.from({ length: count }, (_, idx) => ({
    commentId: `${newsId}-${idx + 1}`,
    authorAvatar: getRandomItem(posters),
    author: `用户${Math.floor(Math.random() * 1000)}`,
    time: `2024-12-${String(Math.floor(Math.random() * 31) + 1).padStart(2, '0')} ${String(Math.floor(Math.random() * 24)).padStart(2, '0')}:${String(Math.floor(Math.random() * 60)).padStart(2, '0')}`,
    content: `这是针对新闻 ${newsId} 的评论内容 ${idx + 1}`,
    likes: Math.floor(Math.random() * 50)
  }));
}

// 生成随机新闻数据
function generateRandomNews(count) {
  return Array.from({ length: count }, (_, i) => {
    const newsId = `${1000 + i + 1}`;
    const commentCount = Math.floor(Math.random() * 10) + 15; // 每条新闻至少有15条评论

    // 前三条新闻使用固定图片
    const poster = i < 3 ? fixedPosters[i] : getRandomItem(posters);

    return {
      id: newsId,
      title: getRandomItem(sampleTitles),
      createTime: `2024-12-${String(i + 1).padStart(2, '0')}`,
      authorAvatar: getRandomItem(posters),  // 随机作者头像
      author: getRandomItem(authors),
      content: generateRandomContent(),
      poster: poster,
      video: getRandomItem(videos), // 修正了 video 变量名错误
      category: getRandomItem(categories),
      collected: Math.random() > 0.5,
      likeCount: Math.floor(Math.random() * 100),
      collectCount: Math.floor(Math.random() * 50),
      commentCount,
      comments: generateComments(newsId, commentCount),
      isContentExpanded:false
    };
  });
}

module.exports = { generateRandomNews };